package com.cf.user.permission.dao;

import com.cf.crud.mapper.BaseMapper;
import com.cf.user.permission.model.RoleWithPermission;
import com.cf.user.permission.model.SystemPermission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoleWithPermissionDao extends BaseMapper<RoleWithPermission> {

    @Select("select * from systemPermission where id in(select permissionId from roleWithPermission where roleId=#{roleId}) order by od desc")
    List<SystemPermission> getPermissionByRoleId(@Param("roleId") long roleId);

    @Select("select * from roleWithPermission where permissionId=#{permissionId}")
    List<RoleWithPermission> selectByPermissionId(@Param("permissionId") long permissionId);

    @Delete("delete from roleWithPermission where roleId = #{roleId}")
    void deleteByRoleId(@Param("roleId") long roleId);
}
